<template>
  <a-popconfirm
    :title="title"
    @confirm="handleSubmit(goodsIds)"
    okText="是"
    cancelText="否"
  >
    <a href="#">删除</a>
  </a-popconfirm>
</template>

<script>
import { removeGoods } from '@/api/basic/goods'
import Web3 from "web3";
var web3
var myContractInstance
export default {
  props: {
    goodsIds: {
      type: String
    },
    data2: {
      type: Array
    }
  },
  data () {
    return {
      title: '确定要删除这' + this.goodsIds.split(',').length + '条记录吗？'
    }
  },
  created () {
  },
  watch: {
    goodsIds: function (val) {
      this.title = '确定要删除这' + val.split(',').length + '条记录吗？'
    }
  },
  methods: {
    handleSubmit (goodsIds) {
      console.log(goodsIds)
      let ids = goodsIds.split(',');
      console.log(ids)
      console.log(this.data2)
      for(let id of ids){
        let userAddress
        console.log(id)
        for(let i=0; i<this.data2.length; i++ ) {
          if(this.data2[i].goodsId.toString() === id.toString()) {
            console.log(2123)
            console.log(this.data2[i])
            userAddress = this.data2[i].owner
          }
        }
        console.log(userAddress)
        this.nft2(parseInt(id), userAddress)
      }
      removeGoods({ 'ids': goodsIds })
        .then(res => {
          if (res.message !== 'error') {
            this.$emit('ok')
          } else {
            this.$message.error('操作失败！')
          }
        })
    },
    nft2 (goodsIds, userAddress) {
      console.log('nft')
      console.log(goodsIds)
      // 删除作品, 查出来的Id=0就表示已经被删了，需要把返回数组中的0过滤掉。
      var result = this.$root.myContractInstance.burn(goodsIds, userAddress, {from: this.$root.userUrl, gas: 2000000})
      return result
    }
  }
}
</script>
